#include "Method.h"

double func1(double x){
  return 1.0/x;
}

double dfunc1(double x){
  return -1.0/(x*x);
}

double func2(double x){
  return x*x*x-3*x*x-x+3;
}

double dfunc2(double x){
  return 3*x*x-6*x-1;
}

double func3(double x){
  return x;
}

double dfunc3(double x){
  return 1;
}

int main(){
  double (*pf1)(double) = &func1;
  double (*pf2)(double) = &func2;
  double (*pf3)(double) = &func3;
  double (*pdf1)(double) = &dfunc1;
  double (*pdf2)(double) = &dfunc2;
  double (*pdf3)(double) = &dfunc3;
  Bisection<double> bct1(50,0.01,pf1,pdf1,-1,2,0.0001);
  cout << "left : " << bct1.get_left() << ", "
       << "right : " << bct1.get_right() << endl
       << "max_iter: " << bct1.get_max_iter() << ", "
       << "tol: " << bct1.get_tol() << endl
       << "f at 2 = " << (*(bct1.get_function()))(2) << endl
       << "df at 2 = " << (*(bct1.get_dfunction()))(2) << endl;
  bct1.set_left(-5);
  bct1.set_right(5);
  bct1.set_max_iter(100);
  bct1.set_tol(1e-4);
  bct1.set_function(pf2);
  bct1.set_dfunction(pdf2);
  cout << "after: " << endl;
   cout << "left : " << bct1.get_left() << ", "
       << "right : " << bct1.get_right() << endl
       << "max_iter: " << bct1.get_max_iter() << ", "
       << "tol: " << bct1.get_tol() << endl
       << "f at 2 = " << (*(bct1.get_function()))(2) << endl
       << "df at 2 = " << (*(bct1.get_dfunction()))(2) << endl;
   cout << "for interval [-5,5] : " << bct1.Is_proper() << endl;
   bct1.set_left(-0.5);
   bct1.set_right(0.5);
   cout << "for interval [-0.5,0.5] : " << bct1.Is_proper() << endl;
   bct1.set_left(0);
   bct1.set_right(1);
   cout << "for interval [0,1] : " << bct1.Is_proper() << endl;
   bct1.set_left(-3.6);
   bct1.set_right(0.4);
   cout << "Bisection method on [-3.6,0.4] :" << endl
        << bct1.solve() << endl;
   bct1.set_left(-0.5);
   bct1.set_right(0.5);
   cout << "Bisection method on [-0.5,0.5] :" << endl
        << bct1.solve() << endl;
   bct1.set_left(2.8);
   bct1.set_right(100);
   cout << "Bisection method on [2.8,100] :" << endl
        << bct1.solve() << endl;
  
}




